package com.freely.domain;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

/**
 *  user_id	bigint	primary key	not null	普通用户id
	user_account	varchar(16)		not null	帐号
	user_password	varchar(16)		not null	密码
	user_email	varchar(16)		not null	邮箱
	user_phone	varchar(11)		not null	手机号
	user_name	varchar(16)		not null	昵称
	user_image	varchar(60)		null	头像
	user_last_login_time	timestamp		not null	上次退出时间
	user_last_update_time	Timestamp		not null	上次更新时间
	user_online	bool		not null	是否在线
	user_forbidden	bool		not null	是否禁用	

 * @author Administrator
 *
 */
public class User {
	private Long user_id;										// 用户id
	@NotBlank(message="用户名不能为空")		
	@Pattern(regexp="^[0-9a-zA-Z]{8,16}$",message="用户名格式错误,请重新输入")
	private String user_account;								// 用户帐号
	@NotBlank(message="密码不能为空")
//	@Pattern(regexp="^[0-9a-zA-Z]{32}$",message="密码格式错误,请重新输入")
	private String user_password;								// 用户密码
	@NotBlank(message="邮箱不能为空")			
	@Email	
	private String user_email;									// 用户邮箱
	@Pattern(regexp="^1[358][0-9]{9}$",message="错误的手机号格式")
	private String user_phone;									// 用户手机号
	@Pattern(regexp="\\S{5,15}",message="昵称不能包含空格且长度限制在5-15")
	private String user_name;									// 用户昵称
	private String user_image;									// 用户头像
	private Date user_last_login_time;							// 用户上次退出时间
	private Date user_last_update_time;							// 用户上次更新个人信息时间
	private Boolean user_online;								// 用户是否在线
	private Boolean user_forbidden;								// 用户是否被禁用
	private Set<Group> groups = new HashSet<>();				// 用户加入的群
	private Set<Message> messages = new HashSet<>();			// 用户消息通知
	
	public Long getUser_id() {
		return user_id;
	}
	public void setUser_id(Long user_id) {
		this.user_id = user_id;
	}
	public String getUser_account() {
		return user_account;
	}
	public void setUser_account(String user_account) {
		this.user_account = user_account;
	}
	public String getUser_password() {
		return user_password;
	}
	public void setUser_password(String user_password) {
		this.user_password = user_password;
	}
	public String getUser_email() {
		return user_email;
	}
	public void setUser_email(String user_email) {
		this.user_email = user_email;
	}
	public String getUser_phone() {
		return user_phone;
	}
	public void setUser_phone(String user_phone) {
		this.user_phone = user_phone;
	}
	public String getUser_name() {
		return user_name;
	}
	public void setUser_name(String user_name) {
		this.user_name = user_name;
	}
	public String getUser_image() {
		return user_image;
	}
	public void setUser_image(String user_image) {
		this.user_image = user_image;
	}
	public Date getUser_last_login_time() {
		return user_last_login_time;
	}
	public void setUser_last_login_time(Date user_last_login_time) {
		this.user_last_login_time = user_last_login_time;
	}
	public Date getUser_last_update_time() {
		return user_last_update_time;
	}
	public void setUser_last_update_time(Date user_last_update_time) {
		this.user_last_update_time = user_last_update_time;
	}
	public Boolean getUser_online() {
		return user_online;
	}
	public void setUser_online(Boolean user_online) {
		this.user_online = user_online;
	}
	public Boolean getUser_forbidden() {
		return user_forbidden;
	}
	public void setUser_forbidden(Boolean user_forbidden) {
		this.user_forbidden = user_forbidden;
	}
	public Set<Group> getGroups() {
		return groups;
	}
	public void setGroups(Set<Group> groups) {
		this.groups = groups;
	}
	public Set<Message> getMessages() {
		return messages;
	}
	public void setMessages(Set<Message> messages) {
		this.messages = messages;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("User [user_id=" + user_id + ", user_account=" + user_account + ", user_password=" + user_password
				+ ", user_email=" + user_email + ", user_phone=" + user_phone + ", user_name=" + user_name
				+ ", user_image=" + user_image + ", user_last_login_time=" + user_last_login_time
				+ ", user_last_update_time=" + user_last_update_time + ", user_online=" + user_online
				+ ", user_forbidden=" + user_forbidden + "]");
		if(groups.size() <= 0) {
			sb.append(" groups is empty ");
		}else {
			sb.append("groups : ");
			for(Group temp : groups) {
				sb.append(temp.getGroup_name() + " , ");
			}
		}
		sb.substring(0, sb.length() - 2);
		if(messages.size() <= 0) {
			sb.append(" messages is empty ");
		}else {
			sb.append("messages : ");
			for(Message temp : messages) {
				sb.append(temp.getMessage_title() + " , ");
			}
		}
		return sb.toString();
	}
}
